#include "StdAfx.h"
#include "Helpers.h"
#include "FillGroupAlgorithmCouplesUnitTests.h"
#include "FillGroupAlgorithmSinglesUnitTests.h"
#include "Group.h"
#include "Graph.h"

extern Vertex* CreateVertex(bool* nameArr, int size);

// tests without input
// create group, insert and remove vertices to it 

// test a graph with n=4,w=2
TestUtils::TestResult FillCouples4On2GroupWithoutSizeLimitation()
{
	// Scenario: creates graph over vertices with  n=4, w=2 
	// creates an empty group and tries to fill it - should be able to add exactly 2 vertices
	
	// Graph = 0110, 0011, 1001, 0101, 1010, 1100
	// when looking for couples to add to a group, we don't want the graph to go over 
	// more than 40 couples..
	Graph graph(400);
	Group group(0);
	graph = TestUtils::CreateGraph4On2(graph);

	//try to fill the group - can only add one vertex: 0011
	// no size limitations for the group
	GreedyFillGroupAlgorithm::FillCouples(graph, group, NULL);

	//validate results:
	//check the group contains only 2 vertices
	if (TestUtils::VerifyIsTrue(group.Size() != 0,"The group is empty") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	if (TestUtils::VerifyIsTrue(group.Size() == 2,"The group doesn't contain the right number of vertices") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	//check that the group is independent
	list<Vertex*>::iterator it = group.Iterator();
	Vertex* v1 = *it;
	it++;
	Vertex* v2 = *it;
	//check the group contains the *right* 2 vertices
	if (TestUtils::VerifyIsTrue((v1->Neighbours(v2)) == false,"The group isn't undependent") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	// check that the directory was updated correctly: All vertices in the graph appear in the graph. All vertices
	// in the group point to the right group.
	if (Algorithms::ValidateVertexDirectoryState(&graph, &group) == false)
	{
		return TestUtils::TestFailed;
	}

	return TestUtils::TestPassed;
}

// Create a graph and a group, try to fill the group, without size limitation
TestUtils::TestResult FillCouples4On2GroupWithSizeLimitation()
{
	// Scenario: creates graph over vertices with  n=4, w=2 
	// creates an empty group and tries to fill it, with size limitation of 1.
	// the group should stay unchanged.
	// then tries to fill it with size limitation of 2. should add exactly 2 vertices to the group.
	// then tries to fill again with size limitation of 3. shouldn't change the group.
	// group shouldn't change
		
	// Graph = 0110, 0011, 1001, 0101, 1010, 1100
	// when looking for couples to add to a group, we don't want the graph to go over 
	// more than 400 couples..
	Graph graph(400);
	Group group(0);
	graph = TestUtils::CreateGraph4On2(graph);

	//try to fill the group - can only add one vertex: 0011
	// size limitations of 1 for the group
	GreedyFillGroupAlgorithm::FillCouples(graph, group,NULL, 1);

	//validate results:
	// check the group is still empty
	if (TestUtils::VerifyIsTrue(group.Size() == 0,"The group isn't empty") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	// try to fill the group again, with size limitation of 2. exactly 2 vertices should be added to the group
	GreedyFillGroupAlgorithm::FillCouples(graph, group,NULL, 2);
	//check the group contains only 2 vertices
	if (TestUtils::VerifyIsTrue(group.Size() == 2,"The group doesn't contain the right number of vertices (2)") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	//check that the group is independent
	list<Vertex*>::iterator it = group.Iterator();
	Vertex* v1 = *it;
	it++;
	Vertex* v2 = *it;
	//check the group contains the *right* 2 vertices
	if (TestUtils::VerifyIsTrue((v1->Neighbours(v2)) == false,"The group isn't undependent") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	// try to fill the group again, with size limitation of 3. group shouldn't change
	GreedyFillGroupAlgorithm::FillCouples(graph, group,NULL, 3);
	//check the group contains only 2 vertices
	if (TestUtils::VerifyIsTrue(group.Size() == 2,"The group doesn't contain the right number of vertices") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	// check that the directory was updated correctly: All vertices in the graph appear in the graph. All vertices
	// in the group point to the right group.
	if (Algorithms::ValidateVertexDirectoryState(&graph, &group) == false)
	{
		return TestUtils::TestFailed;
	}

	return TestUtils::TestPassed;
}
	

